package leetcode.code2012;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int sumOfBeauties(int[] nums) {
		int len = nums.length;
		int[] maxs = new int[len];
		int[] mins = new int[len];
		int max = nums[0];
		for (int i = 1; i < len; i++) {
			maxs[i] = max;
			max = Math.max(max, nums[i]);
		}
		int min = nums[len - 1];
		for (int i = len - 2; i >= 0; i--) {
			mins[i] = min;
			min = Math.min(min, nums[i]);
		}
		int ans = 0;
		for (int i = 1; i < mins.length - 1; i++) {
			int num = nums[i];
			if (num > maxs[i] && num < mins[i]) {
				ans += 2;
			} else if (num > nums[i - 1] && num < nums[i + 1]) {
				ans += 1;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
